package cn.gson.crm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gson.crm.model.dao.LLJ_DetailRepairDao;
import cn.gson.crm.model.dao.LLJ_RepairDao;
import cn.gson.crm.model.pojo.DetailRepair;
import cn.gson.crm.model.pojo.Repair;
import cn.gson.crm.model.pojoVo.LLJ_RepairVo;

@Service
@Transactional(rollbackFor = Exception.class)
public class LLJ_RepairService {

	@Autowired
	private LLJ_RepairDao llj_RepairDao;
	@Autowired
	private LLJ_DetailRepairDao llj_DetailRepairDao;
	
	/**
	 * 维修工单查询
	 * @throws Exception 
	 */
	public List<LLJ_RepairVo> RePairSearch() throws Exception{
		LLJ_RepairVo vo=new LLJ_RepairVo();  
		List<LLJ_RepairVo> listVo=new ArrayList<>();
		try {
			List<Repair> list=(List<Repair>) llj_RepairDao.findAll();
			System.out.println("输出查询结果：");
			System.out.println(list);   
			for(Repair r:list){
				vo.setRepairId(r.getRepairId());
				vo.setContId(r.getContId());//联系人id
				vo.setContLinkMan(r.getContLinkMan());
				vo.setCustomerId(r.getCustomerId());//
				vo.setCustomerName(r.getCustomerName());
				vo.setRepairConnectoName(r.getRepairConnectoName());
				vo.setRepairDatetime(r.getRepairDatetime());
				vo.setRepairMoveId(r.getRepairMoveId());
				vo.setRepairPerson(r.getRepairPerson());//接单人id
				vo.setRepairTel(r.getRepairTel());
				vo.setRepairType(r.getRepairType());
				
				vo.setDrId(r.getDetailRepair().getDrId());//维修工单详情id
				vo.setConnectorState(r.getDetailRepair().getConnectorState());
				vo.setDrAttention(r.getDetailRepair().getDrAttention());
				vo.setDrDeliverDate(r.getDetailRepair().getDrDeliverDate());
				vo.setDrDeptId(r.getDetailRepair().getDrDeptId());//部门id
				vo.setDrDeptName(r.getDetailRepair().getDrDeptName());
				vo.setDrFee(r.getDetailRepair().getDrFee());  
				vo.setDrGuarantee(r.getDetailRepair().getDrGuarantee());
				vo.setDrHitchDescrible(r.getDetailRepair().getDrHitchDescrible());
				vo.setDrProduct(r.getDetailRepair().getDrProduct());//
				vo.setDrProductDate(r.getDetailRepair().getDrProductDate());
				vo.setDrProductSale(r.getDetailRepair().getDrProductSale());
				vo.setDrProductSequ(r.getDetailRepair().getDrProductSequ());//产品序列
				vo.setDrProfit(r.getDetailRepair().getDrProfit());
				vo.setDrReciveFee(r.getDetailRepair().getDrReciveFee());
				vo.setDrRemarks(r.getDetailRepair().getDrRemarks());
				vo.setDrSpeedProgress(r.getDetailRepair().getDrSpeedProgress());
				vo.setDrState(r.getDetailRepair().getDrState());  
				listVo.add(vo); 
			}
		} catch (Exception e) {
			throw new Exception();  
		}  
		return listVo; 
	} 
	    
	/**
	 * 添加维修工单表
	 * @throws Exception 
	 */
	public String addRepairData(Repair repair){
		String judge;
		try { 
			llj_RepairDao.save(repair);
			judge="success";
		} catch (Exception e) {
			return e.getMessage();
			                
		}    
		 return judge;        
	}   
	
	/**  
	 * 找到最新维修工单的id
	 */  
	public Long getNewId(){
		return llj_RepairDao.searchId();  
	} 
	  
	/**
	 * 找到维修工单的数据
	 */       
	public Repair findRepair(Long id){
		System.out.println("开始----------------------------------------");
		System.out.println("输出："+llj_RepairDao.findOne(id));           
		return llj_RepairDao.findOne(id);  
	}
	
	/**
	 * 添加维修工单详情表
	 * @throws Exception 
	 */
	public String addRepairDetailData(DetailRepair d) throws Exception{
		String judge="failed";
		try {
			llj_DetailRepairDao.save(d);  
			judge="success";
		} catch (Exception e) {
			throw new Exception(e);        
		} 
		return judge;   
		
	}
	
	
}
